﻿function showMerge(id) {
    var dv = $("#dvFeedback");
    var currentItemId = "#dv" + id;
    $("#fmItem").html('');
    $("#fmItem").data("Id", id);
    $(currentItemId).clone().appendTo("#fmItem");
    var dvAll = dv.clone();
    dvAll.find(currentItemId).remove();
    dvAll.find(".mergeItem").remove();
    $("#fmItemAll").html('');
    dvAll.appendTo("#fmItemAll");
    $.facebox({ div: '#dvfeebackMerge' });
}
function saveMerge() {
    var ownerId = $("#fmItem").data("Id");
    var mergeId = '';
    var checkBoxes = $("#fmItemAll .feedbackCell1 INPUT[type='checkbox']");
    for (var index = 0; index < checkBoxes.length; index++) {
        var item = $(checkBoxes[index]);
        if (item[0].checked) {
            var hidden = item.next("INPUT[type='hidden']");
            if (ownerId == hidden.val())
                continue;
            mergeId += hidden.val() + "|";
        }
    }
    if (mergeId.length > 0) {
        mergeFeedback(ownerId, mergeId);
    }
}
function mergeFeedback(ownerId, mergeId) {
    $.ajax({
        type: "POST",
        url: "FeedbackView.aspx/MergeFeedback",
        data: "{ownerId:'" + ownerId + "', mergeId:'" + mergeId + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d == true) {
                $(document).trigger('close.facebox')
                updateFeedback();
            }
            else {

            }
        }
    });
}
function toggleMergeFeedback(id, dvexpander) {
    $('#dvMergeContainer' + id).slideToggle('slow');
    changeExpanderIcon(dvexpander);
}
function changeExpanderIcon(expander) {
    var img = $(expander);
    var imgSrc = img.css('background-image') + "";
    if (imgSrc.indexOf("image/plus.jpg") > -1) {
        img.css('background-image', "url(image/minus.jpg)")
    }
    else {
        img.css('background-image', "url(image/plus.jpg)")
    }
}